package script.db
databaseChangeLog(logicalFilePath: 'script/db/yyf_example.groovy') {
    def weight_c = 1
    if(helper.isOracle()){
    weight_c = 3
    }
    if(helper.isSqlServer()){
    weight_c = 2
    }
    changeSet(author: "yufan.yao@hand-china.com", id: "yyf_example-2023-09-20-version-1"){
        if(helper.dbType().isSupportSequence()){
            createSequence(sequenceName: 'yyf_example_s', startValue:"1")
        }
        createTable(tableName: "yyf_example", remarks: "") {
            column(name: "notice_id", type: "bigint",autoIncrement: true,    remarks: "")  {constraints(primaryKey: true)} 
            column(name: "origin_host", type: "varchar(" + 30* weight_c + ")",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "notice_topic", type: "varchar(" + 120* weight_c + ")",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "origin_port", type: "int",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "origin_service_name", type: "varchar(" + 90* weight_c + ")",  remarks: "")  {constraints(nullable:"false")}  
            if(helper.isMysql()){
               column(name: "notice_content", type: "longtext",  remarks: "")  {constraints(nullable:"false")}  
            }
            if(helper.isSqlServer()){
                column(name: "notice_content", type: "longtext",  remarks: "")  {constraints(nullable:"false")}  
            }
            if(helper.isOracle()){
                column(name: "notice_content", type: "clob",  remarks: "")  {constraints(nullable:"false")}  
            }
            if(helper.isPostgresql()){
                column(name: "notice_content", type: "longtext",  remarks: "")  {constraints(nullable:"false")}  
            }
            column(name: "send_date_time", type: "datetime",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "receiver_count", type: "int",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "send_status", type: "varchar(" + 30* weight_c + ")",  remarks: "")  {constraints(nullable:"false")}  
            column(name: "retryable_flag", type: "tinyint",   defaultValue:"1",   remarks: "")  {constraints(nullable:"false")}  
            column(name: "object_version_number", type: "bigint",   defaultValue:"1",   remarks: "")  {constraints(nullable:"false")}  
            column(name: "created_by", type: "bigint",   defaultValue:"-1",   remarks: "")  {constraints(nullable:"false")}  
            column(name: "last_updated_by", type: "bigint",   defaultValue:"-1",   remarks: "")  {constraints(nullable:"false")}  
            column(name: "creation_date", type: "datetime",   defaultValueDate :"2023-09-20 11:08:38",   remarks: "")  {constraints(nullable:"false")}  
            column(name: "last_update_date", type: "datetime",   defaultValueDate :"2023-09-20 11:08:36",   remarks: "")  {constraints(nullable:"false")}  
        }
       createIndex(tableName: "yyf_example", indexName: "yyf_example_n1") {
           column(name: "receiver_count")
           column(name: "send_status")
       }
        addUniqueConstraint(columnNames:"notice_id",tableName:"yyf_example",constraintName: "yyf_example_u1")
    }
}
